<template>
  <div id="tender">
    <h1>基本信息</h1>
    <el-form class="commonFrom" label-width="auto">
      <el-form-item label="招标编号：">
        {{ biddFrom.biddingNo }}
      </el-form-item>
      <el-form-item label="关联工程："> {{ biddFrom.proName }}</el-form-item>
      <el-form-item label="招标单位：">
        {{ biddFrom.biddingEnterprise }}
      </el-form-item>
      <el-form-item label="预估总价："> {{ biddFrom.estimateTotalPrice }}(万元) </el-form-item>
      <el-form-item label="招标类型：" style="margin-right: 400px">
        {{ biddFrom.biddingType ? '定向' : '公开' }}
      </el-form-item>
      <el-form-item label="交付地点：" style="margin-right: 400px">
        {{ biddFrom.province }}{{ biddFrom.city }}{{ biddFrom.area }}{{ biddFrom.detailAddress }}
      </el-form-item>
      <el-form-item label="投标截止时间：">
        {{ biddFrom.bidDateline }}
      </el-form-item>
      <el-form-item label="期望收货日期: ">
        {{ biddFrom.expectTime }}
      </el-form-item>
      <el-form-item label="招标内容：">
        <span v-for="(item, index) in biddFrom.addBiddingContentDtoList" :key="item.id">
          {{ item.materialName }} {{ index + 1 == biddFrom.addBiddingContentDtoList.length ? '' : ';' }}
        </span>
      </el-form-item>
    </el-form>
    <h1>总采购清单</h1>
    <div class="buy_btn" :style="flag ? '' : 'margin:0 0 20px 0;'">
      <div v-if="flag">
        <el-button size="small" class="commonBtn" @click="removeAll"> 清空报价 </el-button>
      </div>
      <div v-if="flag">
        <el-button size="small" class="commonBtn" @click="excelExport">下载采购清单</el-button>
        <el-button size="small" class="commonBtn" @click="importClick">上传报价清单</el-button>
        <div class="upload-wrap">
          <el-upload
            key="excel"
            :multiple="false"
            :action="excelUpload"
            :show-file-list="false"
            :headers="loadHeader"
            :on-error="excelErr"
            :on-success="excelImportSuccess"
            :data="materialObj"
            :before-upload="excelBeforeUpload"
            accept=".xls,.xlsx"
          >
            <template slot="trigger">
              <div ref="excelImport"></div>
            </template>
          </el-upload>
        </div>
      </div>
    </div>
    <div style="margin-bottom: 20px; display: flex" v-if="!bidId">
      <el-table
        :data="biddFrom.addBiddingPurchaseListDtoList"
        border
        width="50%"
        class="tender_table"
        ref="jdjgTable"
        :header-cell-style="{ padding: '0px', background: '#F2F3F7' }"
        :row-class-name="tabRowClassName"
      >
        <el-table-column width="60" align="center" type="index" label="序号">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="品类" align="center" prop="materialName"> </el-table-column>
        <el-table-column label="规格型号" align="center" prop="model"> </el-table-column>
        <el-table-column label="单位" align="center" prop="company"> </el-table-column>
        <el-table-column label="参数指标" align="center" prop="parameterIndex"> </el-table-column>
        <el-table-column label="品牌产地" align="center" prop="brandOrigin"> </el-table-column>
        <el-table-column label="采购数量" align="center" prop="purchaseQuantity"> </el-table-column>
      </el-table>
      <el-table
        :data="biddFrom.bidPurchaseLists"
        border
        width="50%"
        ref="jdjgTable"
        tooltip-effect="light"
        class="bidtable"
        :header-cell-style="{ padding: '0px', background: '#FFF4F2' }"
        :row-class-name="tabRowClassName"
      >
        <el-table-column label="单价(元)" align="center" prop="unitPrice">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-input v-model.trim="scope.row.unitPrice" placeholder="请输入单价" size="mini"> </el-input>
            </div>
            <div v-else>{{ scope.row.unitPrice }}</div>
          </template>
        </el-table-column>
        <el-table-column label="总价(元)" align="center" prop="totalPrice">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-input v-model.trim="scope.row.totalPrice" placeholder="请输入总价" size="mini"> </el-input>
            </div>
            <div v-else>{{ scope.row.totalPrice }}</div>
          </template>
        </el-table-column>
        <el-table-column label="投标数量" align="center" prop="bidNum">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-input v-model.trim="scope.row.bidNum" placeholder="请输入投标数量" size="mini"> </el-input>
            </div>
            <div v-else>{{ scope.row.bidNum }}</div>
          </template>
        </el-table-column>
        <el-table-column label="是否偏差" align="center" prop="deviationState">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-select v-model.trim="scope.row.deviationState" placeholder="请选择" size="mini">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
            <div v-else>{{ scope.row.deviationState | filterDevia }}</div>
          </template>
        </el-table-column>
        <el-table-column label="偏差内容" align="center" prop="deviationContent" show-overflow-tooltip>
          <template slot-scope="scope">
            <div v-if="flag">
              <tool-tip-input
                :deviationContent="scope.row.deviationContent"
                v-model.trim="scope.row.deviationContent"
              ></tool-tip-input>
              <!-- <el-tooltip
                :disabled="disabledTooltip"
                effect="light"
                :content="scope.row.deviationContent"
                placement="top"
              >
                <el-input
                  v-model.trim="scope.row.deviationContent"
                  @input="deviationContentChange"
                  placeholder="请输入偏差内容"
                  size="mini"
                >
                </el-input>
              </el-tooltip> -->
            </div>
            <div v-else class="text_hidde">{{ scope.row.deviationContent }}</div>
          </template>
        </el-table-column>
        <!-- <el-table-column label="单价(元)" align="center" prop="unitPrice">
          <template slot-scope="scope" v-if="flag">
            <div>
              <el-input v-model.trim="scope.row.unitPrice" placeholder="请输入单价" size="mini"> </el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="总价(元)" align="center" prop="totalPrice">
          <template slot-scope="scope" v-if="flag">
            <div>
              <el-input v-model.trim="scope.row.totalPrice" placeholder="请输入总价" size="mini"> </el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="投标数量" align="center" prop="bidNum">
          <template slot-scope="scope" v-if="flag">
            <div>
              <el-input v-model.trim="scope.row.bidNum" placeholder="请输入投标数量" size="mini"> </el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="是否偏差" align="center" prop="deviationState">
          <template slot-scope="scope" v-if="flag">
            <div>
              <el-select v-model.trim="scope.row.deviationState" placeholder="请选择" size="mini">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="偏差内容" align="center" prop="deviationContent">
          <template slot-scope="scope" v-if="flag">
            <div>
              <el-tooltip
                :disabled="disabledTooltip"
                effect="light"
                :content="scope.row.deviationContent"
                placement="top"
              >
                <el-input
                  v-model.trim="scope.row.deviationContent"
                  @input="deviationContentChange"
                  placeholder="请输入偏差内容"
                  size="mini"
                >
                </el-input>
              </el-tooltip>
            </div>
          </template>
        </el-table-column> -->
      </el-table>
    </div>
    <div style="margin-bottom: 20px; display: flex" v-else>
      <el-table
        :data="biddFrom.bidPurchaseLists"
        border
        key="bidding"
        width="50%"
        class="tender_table"
        ref="jdjgTable"
        :header-cell-style="{ padding: '0px', background: '#F2F3F7' }"
        :row-class-name="tabRowClassName"
      >
        <el-table-column width="60" align="center" type="index" label="序号">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="品类" align="center" prop="materialName"> </el-table-column>
        <el-table-column label="规格型号" align="center" prop="specModel"> </el-table-column>
        <el-table-column label="单位" align="center" prop="unit"> </el-table-column>
        <el-table-column label="参数指标" align="center" prop="parameter"> </el-table-column>
        <el-table-column label="品牌产地" align="center" prop="brandOrigin"> </el-table-column>
        <el-table-column label="采购数量" align="center" prop="purchaseQuantity"> </el-table-column>
      </el-table>
      <el-table
        :data="biddFrom.bidPurchaseLists"
        border
        key="bid"
        width="50%"
        ref="jdjgTable"
        tooltip-effect="light"
        class="bidtable"
        :header-cell-style="{ padding: '0px', background: '#FFF4F2' }"
        :row-class-name="tabRowClassName"
      >
        <el-table-column label="单价(元)" align="center" prop="unitPrice">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-input v-model.trim="scope.row.unitPrice" placeholder="请输入单价" size="mini"> </el-input>
            </div>
            <div v-else>{{ scope.row.unitPrice }}</div>
          </template>
        </el-table-column>
        <el-table-column label="总价(元)" align="center" prop="totalPrice">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-input v-model.trim="scope.row.totalPrice" placeholder="请输入总价" size="mini"> </el-input>
            </div>
            <div v-else>{{ scope.row.totalPrice }}</div>
          </template>
        </el-table-column>
        <el-table-column label="投标数量" align="center" prop="bidNum">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-input v-model.trim="scope.row.bidNum" placeholder="请输入投标数量" size="mini"> </el-input>
            </div>
            <div v-else>{{ scope.row.bidNum }}</div>
          </template>
        </el-table-column>
        <el-table-column label="是否偏差" align="center" prop="deviationState">
          <template slot-scope="scope">
            <div v-if="flag">
              <el-select v-model.trim="scope.row.deviationState" placeholder="请选择" size="mini">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
            <div v-else>{{ scope.row.deviationState | filterDevia }}</div>
          </template>
        </el-table-column>
        <el-table-column label="偏差内容" align="center" prop="deviationContent" show-overflow-tooltip>
          <template slot-scope="scope">
            <div v-if="flag">
              <tool-tip-input
                :deviationContent="scope.row.deviationContent"
                v-model.trim="scope.row.deviationContent"
              ></tool-tip-input>
              <!-- <el-tooltip
                :disabled="disabledTooltip"
                effect="light"
                :content="scope.row.deviationContent"
                placement="top"
              >
                <el-input
                  v-model.trim="scope.row.deviationContent"
                  @input="deviationContentChange"
                  placeholder="请输入偏差内容"
                  size="mini"
                >
                </el-input>
              </el-tooltip> -->
            </div>
            <div v-else class="text_hidde">{{ scope.row.deviationContent }}</div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <h1>发票及税金</h1>
    <el-form label-width="auto" class="commonFrom">
      <el-form-item label="报价要求：">
        {{ biddFrom.quoteAsk ? '不含税' : '含税' }}
      </el-form-item>
      <el-form-item label="发票要求：">
        <div>
          <span>{{
            biddFrom.billAsk === 0 ? '增值税专用发票' : biddFrom.billAsk === 1 ? '增值税普通发票' : '普通发票'
          }}</span>
        </div>
      </el-form-item>
    </el-form>
    <h1>投标文件{{ flag ? '上传' : '下载' }}</h1>
    <el-button style="margin-top: 20px" size="small" type="primary" class="commonBtn1" @click="uploadClick" v-if="flag">
      上传附件
    </el-button>
    <div v-if="flag" class="upload-wrap">
      <el-upload
        class="upload-demo"
        :headers="loadHeader"
        multiple
        accept=".doc,.docx,.pdf"
        :action="urlUpload"
        :on-remove="fileRemove"
        :on-success="uploadSuccess"
        :before-upload="beforeUpload"
        :on-exceed="onExceed"
        :file-list="fileList"
      >
        <template slot="trigger">
          <div ref="biddUpload"></div>
        </template>
      </el-upload>
    </div>
    <div v-else class="download">
      <el-upload class="upload-demo" multiple :file-list="fileList" action :on-preview="downFile">
        <template slot="trigger">
          <div ref="biddUpload"></div>
        </template>
      </el-upload>
    </div>
    <h1>
      支付投标保证金
      <span> （投标需要缴纳保证金，流标后自动返还，中标可转换为履约保证金） </span>
    </h1>
    <el-form label-width="auto" class="commonFrom">
      <el-form-item label="保证金金额:" style="margin-right: 400px">
        <span>{{ biddFrom.bidBond }}万元</span>
        <el-button style="margin-left: 50px" size="small" type="primary" class="commonBtn1" v-if="flag">
          去支付
        </el-button>
      </el-form-item>
      <el-form-item label="到账金额:" style="margin-right: 400px" v-if="flag">
        0
        <i class="iconfont icon-shuaxin" style="margin-left: 10px; color: #fa7355"></i>
      </el-form-item>
    </el-form>
    <h1>投标说明</h1>
    <el-input
      style="margin: 20px 0"
      type="textarea"
      :autosize="{ minRows: 3 }"
      placeholder="请输入投标说明"
      v-model.trim="biddFrom.bidExplain"
      v-if="flag"
    >
    </el-input>
    <div style="margin: 20px 0" v-else>{{ biddFrom.bidExplain }}</div>
    <div style="margin-bottom: 20px" v-if="flag">
      <h1>审核人员</h1>
      <el-button
        style="margin: 20px 0"
        size="small"
        type="primary"
        class="commonBtn1 mgn"
        icon="iconfont icon-add"
        @click="addReviewer"
        >添加审核人员</el-button
      >
      <el-form class="commonFrom auditfrom" label-width="110px">
        <el-form-item v-for="(item, index) in reviewerList" :key="index" :label="'审核人员' + (index + 1) + '：'">
          <el-input
            style="width: 220px"
            class="no_border"
            disabled
            size="small"
            placeholder="请选择审核人员"
            v-model.trim="item.reviewName"
          >
            <el-button @click="personnelSelect('reviewer', index)" slot="append">选择</el-button>
          </el-input>
          <i class="iconfont icon-guanbianniu" @click="colseReviewer(index)"></i>
        </el-form-item>
      </el-form>
    </div>
    <div class="footer" v-if="flag">
      <el-button size="small" class="commonBtn footBtn" @click="closeBtn">取消</el-button>
      <el-button size="small" class="commonBtn footBtn" @click="saveBtn">保存</el-button>
      <el-button size="small" class="commonBtn1 footBtn" @click="subBtn">确定</el-button>
    </div>

    <el-dialog
      width="765px"
      :center="true"
      title="选择审核人"
      append-to-body
      :close-on-click-modal="false"
      :visible.sync="personVisible"
      v-if="personVisible"
    >
      <personnel-select :type="personType" :index="reviewerIndex" @close="personClose"></personnel-select>
    </el-dialog>
  </div>
</template>

<script>
import personnelSelect from './PersonnelSelect.vue'
import ToolTipInput from './ToolTipInput.vue'
export default {
  props: {
    check: {
      type: Boolean,
      default: true
    },
    // 招标书id
    Id: {
      type: Number
    },
    // 投标书id
    bidId: {
      type: Number,
      default: null
    },
    bidFrom: {
      type: Object
    }
  },
  data() {
    return {
      fileSuccess: true,
      num: 0,
      materialObj: {},
      excelUpload: this.GLOBAL.weburl + '/excel/allListImport',
      disabledTooltip: true,
      bidid: this.bidId,
      biddingId: this.Id,
      // 查看或者编辑
      flag: this.check,
      options: [
        {
          label: '无偏差',
          value: 0
        },
        {
          label: '正偏差',
          value: 1
        },
        {
          label: '负偏差',
          value: 2
        }
      ],
      urlUpload: this.GLOBAL.weburl + '/api/file/upload',
      biddFrom: {},
      // 定时器
      timer: null,
      fileList: [],
      reviewerList: [
        {
          reviewName: '',
          userId: ''
        }
      ],
      personVisible: false,
      personType: '',
      reviewerIndex: ''
    }
  },
  components: { personnelSelect, ToolTipInput },
  computed: {
    // 上传携带token
    loadHeader() {
      let token = this.common.getCookie('materialsToken')
      const header = {}
      header[this.GLOBAL.tokenName] = token
      return header
    }
  },
  mounted() {
    if (this.bidFrom) {
      this.biddFrom = this.bidFrom
      this.$set(this.biddFrom, 'bidFileList', this.bidFrom.biddingFile)
      this.biddFrom.bidFileList.forEach(item => {
        this.fileList.push({
          name: item.fileName,
          url: item.fileAddress
        })
      })
      // 设置审核人
      this.reviewerList = this.biddFrom.addReviewerDtoList
      // 设置投标说明
      this.$set(this.biddFrom, 'bidExplain', this.bidFrom.bids[0]['bidExplain'])
    } else {
      this.getData()
    }
  },
  methods: {
    downloadFile(res, filename) {
      var a = document.createElement('a')
      // var blob = new Blob([res], {
      //   type: filename.split('.')[1]
      // })
      // this.dataURLtoBlob
      var blob = this.dataURLtoBlob(res, filename)
      var url = window.URL.createObjectURL(blob)
      a.href = url
      a.download = filename
      a.click()
      window.URL.revokeObjectURL(url)
    },

    dataURLtoBlob(base64Str, filename) {
      var bstr = atob(base64Str),
        n = bstr.length,
        u8arr = new Uint8Array(n)
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n)
      }
      // 下载的是excel格式的文件
      return new Blob([u8arr], { type: filename.split('.')[1] })
    },
    // 导入采购清单
    importClick() {
      this.$refs.excelImport.click()
    },
    // 成功时
    excelImportSuccess(res) {
      if (res.code === 0) {
        let arr = []
        res.data.forEach(item => {
          if (item.specModel) {
            arr.push({
              unitPrice: item.unitPrice,
              bidNum: item.bidNum,
              totalPrice: item.totalPrice,
              deviationContent: item.deviationContent,
              deviationState: item.deviationState
            })
          }
        })
        // this.biddFrom.bidPurchaseLists = arr
        this.biddFrom.bidPurchaseLists.forEach((item, index) => {
          Object.assign(item, arr[index])
        })
        this.$message.success(res.msg)
      } else {
        this.$message.error(res.msg)
      }
    },
    // 失败时
    excelErr(err) {
      console.log(err)
    },
    excelBeforeUpload(file) {
      let hz = file.name.substring(file.name.lastIndexOf('.') + 1)
      const isExcel = hz === 'xlsx' || hz === 'xls'
      if (!isExcel) {
        this.$message.error(`只能选择excel文件`)
        return false
      }

      // 判断文件大小
      let fileSize = file.size / 1024 / 1024 < 5
      if (!fileSize) {
        this.$message.error('上传文件大小不能超过 5MB')
        return false
      }
      this.$set(this.materialObj, 'bidId', this.biddingId)
      return isExcel && fileSize
    },
    // 导出采购清单
    excelExport() {
      this.$https({
        method: 'get',
        url: '/excel/allListExport?bidId=' + this.biddingId
      })
        .then(res => {
          console.log(res)
          if (res.code === 0) {
            this.downloadFile(res.data, '采购清单.xls')
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    downFile(file) {
      this.common
        .getBlob(file.url)
        .then(res => {
          this.common.saveAs(res, file.name)
        })
        .catch(err => {
          console.log(err)
        })
    },

    closeBtn() {
      this.$emit('close')
      this.biddFrom = {}
      // 定时器
      clearTimeout(this.timer)
      this.timer = null
      this.fileList = []
      this.reviewerList = [
        {
          reviewName: '',
          userId: ''
        }
      ]
      this.personVisible = false
      this.personType = ''
      this.reviewerIndex = ''
    },
    // 提交投标书
    subBtn() {
      this.$set(this.biddFrom, 'processSon', 1)
      if (!this.bidId) {
        this.biddFrom.addBiddingPurchaseListDtoList.forEach((item, index) => {
          this.biddFrom.bidPurchaseLists.forEach((item2, index2) => {
            if (index === index2) {
              Object.assign(item2, item)
            }
          })
        })
        this.biddFrom.bidPurchaseLists = JSON.parse(
          JSON.stringify(this.biddFrom.bidPurchaseLists)
            .replace(/company/g, 'unit')
            .replace(/model/g, 'specModel')
            .replace(/parameterIndex/g, 'parameter')
        )
      }

      if (!this.fileSuccess) {
        this.$message.error('请等待文件上传完毕')
        return false
      } else {
        this.biddFrom.bidFileList = []
        if (this.fileList.length) {
          this.fileList.forEach(item => {
            if (item.url) {
              this.biddFrom.bidFileList.push({
                fileAddress: item.url,
                fileName: item.name
              })
            } else {
              this.biddFrom.bidFileList.push({
                fileAddress: item.response.data,
                fileName: item.name
              })
            }
          })
        }
      }
      // 过滤不为空的审核人
      this.biddFrom.addReviewerDtoList = this.reviewerList.filter(item => {
        return item.userId != ''
      })
      if (!this.biddFrom.addReviewerDtoList.length) {
        this.$message.error('请选择审核人')
        return false
      } else if (!this.biddFrom.bidFileList.length) {
        this.$message.error('请上传投标文件')
        return false
      }
      this.saveBid()
    },
    // 保存投标书
    saveBtn() {
      if (this.bidId) {
        this.$set(this.biddFrom, 'processSon', 0)
      } else {
        this.$set(this.biddFrom, 'processSon', 0)
        this.biddFrom.addBiddingPurchaseListDtoList.forEach((item, index) => {
          this.biddFrom.bidPurchaseLists.forEach((item2, index2) => {
            if (index === index2) {
              Object.assign(item2, item)
            }
          })
        })
        this.biddFrom.bidPurchaseLists = JSON.parse(
          JSON.stringify(this.biddFrom.bidPurchaseLists)
            .replace(/company/g, 'unit')
            .replace(/model/g, 'specModel')
            .replace(/parameterIndex/g, 'parameter')
        )
      }

      if (!this.fileSuccess) {
        this.$message.error('请等待文件上传完毕')
        return false
      } else {
        if (this.fileList.length) {
          this.fileList.forEach(item => {
            if (item.url) {
              this.biddFrom.bidFileList.push({
                fileAddress: item.url,
                fileName: item.name
              })
            } else {
              this.biddFrom.bidFileList.push({
                fileAddress: item.response.data,
                fileName: item.name
              })
            }
          })
        } else {
          this.biddFrom.bidFileList = []
        }
      }
      // 过滤不为空的审核人
      this.biddFrom.addReviewerDtoList = this.reviewerList.filter(item => {
        return item.userId != ''
      })
      this.saveBid()
    },
    saveBid() {
      this.biddFrom.addReviewerDtoList.forEach((item, index) => {
        this.$set(item, 'reviewOrder', index)
      })
      this.$https({
        method: 'post',
        url: '/biddingSquare/releaseBid',
        data: this.biddFrom
      })
        .then(res => {
          if (res.code === 0) {
            this.$message.success('投标成功')
            this.fileList = []
            this.closeBtn()
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 清空投标清单
    removeAll() {
      this.$confirm('是否清空投标清单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.biddFrom.bidPurchaseLists.forEach(element => {
            for (const key in element) {
              if (
                key == 'unitPrice' ||
                key == 'totalPrice' ||
                key == 'bidNum' ||
                key == 'deviationState' ||
                key == 'deviationContent'
              ) {
                element[key] = ''
              }
            }
          })
          this.$message({
            type: 'success',
            message: '清空成功!'
          })
        })
        .catch(() => {})
    },
    //选择人员弹窗关闭
    personClose(e) {
      this.reviewerList[this.reviewerIndex].reviewName = e.userName
      this.reviewerList[this.reviewerIndex].userId = e.id
      this.personVisible = false
    },
    //选择联系人
    personnelSelect(type, index) {
      this.reviewerIndex = index
      this.personVisible = true
      this.personType = type
    },
    //添加审核人
    addReviewer() {
      if (this.reviewerList.length < 5) {
        this.reviewerList.push({
          reviewName: '',
          userId: ''
        })
      } else {
        this.$message.error('最多添加5位审核人员')
      }
    },
    //删除审核人
    colseReviewer(index) {
      if (this.reviewerList.length > 1) {
        this.$confirm('是否删除审核人?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.reviewerList.splice(index, 1)
          })
          .catch(() => {})
      } else {
        this.$message.error('审核人不能少于一个')
      }
    },
    getData() {
      this.$https({
        url: '/biddingSquare/bidWritePageInfo',
        method: 'post',
        data: {
          bidId: this.bidid,
          biddingId: this.biddingId
        }
      }).then(res => {
        if (res.code === 0) {
          this.biddFrom = res.data
          // 如果投标id不存在 代表第一次投标
          if (this.bidId === null) {
            this.biddFrom.processSon = 0
            this.biddFrom.bidEnterprise = localStorage.getItem('enterpriseName')
            this.biddFrom.bidEnterpriseId = localStorage.getItem('enterpriseId')
            this.biddFrom.biderId = localStorage.getItem('userId')
            this.biddFrom.biderName = localStorage.getItem('userName')
            // 招标书id
            this.biddFrom.biddingId = this.Id
            // 当前投标书id
            this.biddFrom.id = null
            // 设置审核人
            this.biddFrom.addReviewerDtoList = []
            // 设置文件列表
            this.biddFrom.bidFileList = []
            // 设置投标采购清单
            this.biddFrom.bidPurchaseLists = []
            this.$set(this.biddFrom, 'bidExplain', '')
            // 根据采购清单的长度设置投标清单
            for (let i = 0; i < res.data.addBiddingPurchaseListDtoList.length; i++) {
              this.biddFrom.bidPurchaseLists.push({
                unitPrice: '',
                totalPrice: '',
                bidNum: '',
                deviationState: '',
                deviationContent: ''
              })
            }
          } else {
            // 如果投标id存在，代表为编辑或者查看
            this.$set(this.biddFrom, 'bidFileList', res.data.biddingFile)
            // 招标书id
            this.biddFrom.biddingId = this.Id
            // 当前投标书id
            this.biddFrom.id = this.bidId
            this.biddFrom.bidFileList.forEach(item => {
              this.fileList.push({
                name: item.fileName,
                url: item.fileAddress
              })
            })
            if (this.fileList.length) {
              this.num = this.fileList.length
            }
            // 设置审核人
            if (!this.biddFrom.addReviewerDtoList) {
              this.reviewerList = [
                {
                  reviewName: '',
                  userId: ''
                }
              ]
            } else {
              this.reviewerList = this.biddFrom.addReviewerDtoList.length
                ? this.biddFrom.addReviewerDtoList
                : [
                    {
                      reviewName: '',
                      userId: ''
                    }
                  ]
            }

            // 设置投标说明
            this.$set(this.biddFrom, 'bidExplain', res.data.bids[0]['bidExplain'])
          }
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 删除文件
    fileRemove(file, files) {
      this.fileList = files
      this.num = this.fileList.length
    },
    // 文件上传前进行文件大小检测
    beforeUpload(file) {
      this.fileSuccess = false
      const isLt = file.size / 1024 / 1024 / 50 <= 1
      if (!isLt) {
        this.$message.error('单个文件大小不能超过50M,请检查文件大小并重新尝试')
      }
      return isLt
    },
    // 文件上传前判断是否超过同时上传文件个数限制
    onExceed() {
      this.$message.error('最多支持同时上传3个文件，请重新上传')
    },
    // 上传成功时的回调
    uploadSuccess(val, e, el) {
      this.num++
      if (this.num == el.length) {
        this.num = el.length
        this.fileSuccess = true
      }
      clearTimeout(this.timer)
      this.timer = setTimeout(() => {
        this.$message.success('上传成功')
      }, 300)

      this.fileList = el
    },
    // 触发上传
    uploadClick() {
      this.$refs.biddUpload.click()
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    }
  },
  filters: {
    filterDevia(val) {
      return val === 0 ? '无偏差' : val === 1 ? '正偏差' : '负偏差'
    }
  },
  watch: {
    Id() {
      return (this.biddingId = this.Id)
    },
    check() {
      return (this.flag = this.check)
    },
    bidId() {
      this.bidid = this.bidId
      this.getData()
      return
    }
  }
}
</script>
<style lang="less">
#tender {
  .bidtable {
    .el-input--mini .el-input__inner {
      height: 26px;
      line-height: 26px;
      padding: 0 5px;
    }
  }
  .el-form-item__label-wrap {
    margin-left: 0 !important;
  }
  .el-table__body {
    .cell {
      height: 28px;
      line-height: 28px;
    }
  }
}
.upload-wrap {
  // display: flex;
  // .upload-demo {
  //   margin-top: 20px;
  //   margin-left: 20px;
  // }
  .el-upload {
    display: none;
  }
  .el-upload-list {
    display: flex;
    align-items: center;
    width: 600px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    .el-upload-list__item {
      width: 260px;
      margin: 20px 30px 0 0;
      background: #f0f1f2;
      border: 1px solid #d6d6d6;
    }
    .el-icon-close {
      &:hover {
        color: #fa7355;
      }
    }
  }
}
</style>
<style lang="less" scoped>
#tender {
  .text_hidde {
    // width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .download {
    margin-bottom: 20px;
    /deep/.el-upload-list__item-name:hover {
      color: #fa7355;
    }
    /deep/ .el-upload {
      display: none !important;
    }
    /deep/ .el-upload-list {
      display: flex;
      align-items: center;
      width: 600px;
      flex-wrap: wrap;
      .el-upload-list__item {
        width: 260px;
        margin: 20px 30px 0 0;
        background: #f0f1f2;
        border: 1px solid #d6d6d6;
      }
      .el-upload-list__item.is-success .el-upload-list__item-status-label {
        display: none;
      }
      .el-upload-list__item .el-icon-close {
        display: none;
        &:hover {
          display: none;
        }
      }
      .el-upload-list__item .el-icon-close-tip {
        display: none;
        &:hover {
          display: none;
        }
      }
    }
  }
  .footer {
    display: flex;
    justify-content: center;
    .footBtn {
      width: 130px;
    }
  }
  .auditfrom {
    .el-form-item {
      width: 41% !important;
    }
  }

  .buy_btn {
    display: flex;
    justify-content: space-between;
    margin: 20px 0;
  }
}
.commonFrom {
  margin-top: 10px;
  width: 80%;
  .el-form-item {
    width: 40% !important;
  }
  .performance_text {
    color: #999;
    font-size: 14px;
  }
  .icon-guanbianniu {
    font-size: 16px;
    cursor: pointer;
    margin-left: 10px;
  }
  .icon-guanbianniu:hover {
    color: #fa7355;
  }
}
h1 {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  padding-left: 10px;
  border-left: 4px solid #fa7355;
  span {
    font-weight: normal;
    color: #999;
  }
}
</style>
